package kr.hkit.jenny.coffee.dto;

import kr.hkit.myframework.uicomp.Utils;

public class SalesRecord {

	/**
	 * pdCode: 제품코드 pdName: 제품명 pdPrice: 제품 단가 amount: 판매수량 pMargin: 마진율
	 * sellingPrice: 판매금액 (=단가*수량) tax: 부가세액 (=판매금액/11, 소수점 첫째 자리에서 올림) supply:
	 * 공급가액 (=판매금액-부가세액) margin: 마진액 (=공급가액*마진율, 소수점 첫째 자리에서 반올림)
	 */
	private String pdCode;
	private String pdName;
	private int pdPrice;
	private int amount;
	private double pMargin;

	private int sellingPrice;
	private int tax;
	private int supply;
	private int margin;

	public SalesRecord(String pdCode, String pdName) {
		this.pdCode = pdCode;
		this.pdName = pdName;
	}

	public SalesRecord(String pdCode, int pdPrice, int amount, double pMargin) {
		this.pdCode = pdCode;
		this.pdPrice = pdPrice;
		this.amount = amount;
		this.pMargin = pMargin;
	}

	public SalesRecord(String pdCode, String pdName, int pdPrice, int amount,
			double pMargin) {
		this.pdCode = pdCode;
		this.pdName = pdName;
		this.pdPrice = pdPrice;
		this.amount = amount;
		this.pMargin = pMargin;
	}

	public SalesRecord(String pdCode, String pdName, int pdPrice, int amount,
			double pMargin, int sellingPrice, int tax, int supply, int margin) {
		this.pdCode = pdCode;
		this.pdName = pdName;
		this.pdPrice = pdPrice;
		this.amount = amount;
		this.pMargin = pMargin;
		this.sellingPrice = sellingPrice;
		this.tax = tax;
		this.supply = supply;
		this.margin = margin;
	}

	public SalesRecord() {
	}

	public String getPdCode() {
		return pdCode;
	}

	public void setPdCode(String pdCode) {
		this.pdCode = pdCode;
	}

	public String getPdName() {
		return pdName;
	}

	public void setPdName(String pdName) {
		this.pdName = pdName;
	}

	public int getPdPrice() {
		return pdPrice;
	}

	public void setPdPrice(int pdPrice) {
		this.pdPrice = pdPrice;
	}

	public int getAmount() {
		return amount;
	}

	public void setAmount(int amount) {
		this.amount = amount;
	}

	public double getpMargin() {
		return pMargin;
	}

	public void setpMargin(double pMargin) {
		this.pMargin = pMargin;
	}

	public int getSellingPrice() {
		setSellingPrice();
		return sellingPrice;
	}

	public int getTax() {
		setTax();
		return tax;
	}

	public int getSupply() {
		setSupply();
		return supply;
	}

	public int getMargin() {
		setMargin();
		return margin;
	}

	public void setSellingPrice() {
		this.sellingPrice = pdPrice * amount;
	}

	public void setTax() {
		this.tax = (int) Math.ceil(getSellingPrice() / 11);
	}

	public void setSupply() {
		this.supply = getSellingPrice() - getTax();
	}

	public void setMargin() {
		this.margin = (int) Math.round(getSupply() * pMargin);
	}

	public String[] toArray() {
		return new String[] { pdCode, pdName, Utils.getComma(pdPrice),
				Utils.eightDigit(amount), String.valueOf(pMargin),
				Utils.getComma(sellingPrice), String.valueOf(tax),
				Utils.getComma(supply), String.valueOf(margin) };
	}

	@Override
	public String toString() {
		return String
				.format("SalesRecord [pdCode=%s, pdName=%s, pdPrice=%s, amount=%s, pMargin=%s, getSellingPrice()=%s, getTax()=%s, getSupply()=%s, getMargin()=%s]",
						pdCode, pdName, pdPrice, amount, pMargin,
						getSellingPrice(), getTax(), getSupply(), getMargin());
	}

	
}
